/**
 * Anagram class
 *
 * @author sergei
 *
 * @date 25 Jan 2013
 */

import java.util.Scanner;
import java.util.Arrays;

class Anagram {
    /**
     * Method inputWord returns line inputed by user.
     * @result String User's input.
     */
    private static String inputWord() {
	    System.out.print("Enter word combination: ");
        
        Scanner scanner = new Scanner(System.in);
        String word = scanner.nextLine();

	    return word;
    }
    
    /**
     * Method isAnagram checks if the input couple of words are anagrams
     * (consist of same letters).
     */
    private static boolean isAnagram(String first, String second) {
        int[] firstCodePointsArray = 
                Anagram.toNormalizedIntArray(first.replaceAll("\\s", ""));
		int[] secondCodePointsArray = 
                Anagram.toNormalizedIntArray(second.replaceAll("\\s", ""));
		
		Arrays.sort(firstCodePointsArray);
		Arrays.sort(secondCodePointsArray);

        return Arrays.equals(firstCodePointsArray, secondCodePointsArray);
    }
    
    /**
     * Method toNormalizedIntArray converts String variable to array of int values,
     * where every value is a codePoint of symbol.
     * @param String    value String value to be converted.
     * @return int[]       Array of int codePoints symbols.
     */
    private static int[] toNormalizedIntArray(String value) {
        int[] codePoints = new int[value.length()];
        for (int i = 0; i < value.length(); i++) {
            codePoints[i] = Character.toLowerCase(value.codePointAt(i));
        }
        return codePoints;
    }

    public static void main(String[] args) {
        String first;
        String second;   // Words to check.
        
        first = Anagram.inputWord();
        second = Anagram.inputWord();
        
        boolean result;
        result = Anagram.isAnagram(first, second);

        System.out.println(result);
    }
}


